package Dao;

import Bean.Brand;
import Utils.DBUtils;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

public class BrandDao {
    //重数据库查询所有品牌
    public static ArrayList<Brand> getAllBrand(){
        String sql = "select * from brand";
        ResultSet rs = DBUtils.query(sql);
        ArrayList<Brand> list = new ArrayList<>();
        try {
            while (rs.next()){
                int id = rs.getInt(1);
                String name = rs.getString(2);
                Brand b = new Brand(id, name);
                list.add(b);
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return list;
    }
}
